package utils;

import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

import beans.ReturnHintBean;
import beans.TimeoutBean;

/**
 * Created by Administrator on 2018/8/8.
 */

public class ReturnHintSortUtils {

    /**
     * 物品
     * @param list
     * @param flag
     */
    public static void sortReturnHintGoods(List<ReturnHintBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<ReturnHintBean>() {
                @Override
                public int compare(ReturnHintBean o1, ReturnHintBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getGoodsName(), o1.getGoodsName()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getGoodsName(), o1.getGoodsName()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<ReturnHintBean>() {
                @Override
                public int compare(ReturnHintBean o1, ReturnHintBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getGoodsName(), o1.getGoodsName()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getGoodsName(), o1.getGoodsName()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    /**
     * 供应商
     * @param list
     * @param flag
     */
    public static void sortReturnHintSupplier(List<ReturnHintBean> list,boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<ReturnHintBean>() {
                @Override
                public int compare(ReturnHintBean o1, ReturnHintBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getManufacturer(), o1.getManufacturer()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getManufacturer(), o1.getManufacturer()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<ReturnHintBean>() {
                @Override
                public int compare(ReturnHintBean o1, ReturnHintBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getManufacturer(), o1.getManufacturer()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getManufacturer(), o1.getManufacturer()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    /**
     * 取出时间
     * @param list
     * @param flag
     */
    public static void sortReturnHint(List<ReturnHintBean> list,boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<ReturnHintBean>() {
                @Override
                public int compare(ReturnHintBean o1, ReturnHintBean o2) {
                    long time1 = Long.parseLong(TimeUtil.dateToStampSeconds(o1.getTakeTime()));
                    long time2 = Long.parseLong(TimeUtil.dateToStampSeconds(o2.getTakeTime()));
                    if (time2 - time1 < 0) {
                        return 1;
                    } else if (time2 - time1 == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<ReturnHintBean>() {
                @Override
                public int compare(ReturnHintBean o1, ReturnHintBean o2) {
                    long time1 = Long.parseLong(TimeUtil.dateToStampSeconds(o1.getTakeTime()));
                    long time2 = Long.parseLong(TimeUtil.dateToStampSeconds(o2.getTakeTime()));
                    if (time2 - time1 > 0) {
                        return 1;
                    } else if (time2 - time1 == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    /**
     * 操作人
     * @param list
     * @param flag
     */
    public static void sortReturnHintOperator(List<ReturnHintBean> list,boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<ReturnHintBean>() {
                @Override
                public int compare(ReturnHintBean o1, ReturnHintBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getOperator(), o1.getOperator()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getOperator(), o1.getOperator()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<ReturnHintBean>() {
                @Override
                public int compare(ReturnHintBean o1, ReturnHintBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getOperator(), o1.getOperator()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getOperator(), o1.getOperator()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    /**
     * 规格
     * @param list
     * @param flag
     */

    public static void sortReturnHintSpecification(List<ReturnHintBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<ReturnHintBean>() {
                @Override
                public int compare(ReturnHintBean o1, ReturnHintBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getSpecification(), o1.getSpecification()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getSpecification(), o1.getSpecification()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<ReturnHintBean>() {
                @Override
                public int compare(ReturnHintBean o1, ReturnHintBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getSpecification(), o1.getSpecification()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getSpecification(), o1.getSpecification()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    /**
     * 数量
     * @param list
     * @param flag
     */
    public static void sortReturnHintNumber(List<ReturnHintBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<ReturnHintBean>() {
                @Override
                public int compare(ReturnHintBean o1, ReturnHintBean o2) {
                    int count2 = Integer.parseInt(o2.getNumber());
                    int count1 = Integer.parseInt(o1.getNumber());
                    if (count2 - count1 < 0) {
                        return 1;
                    } else if (count2 - count1 == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<ReturnHintBean>() {
                @Override
                public int compare(ReturnHintBean o1, ReturnHintBean o2) {
                    int count2 = Integer.parseInt(o2.getNumber());
                    int count1 = Integer.parseInt(o1.getNumber());
                    if (count2 - count1 > 0) {
                        return 1;
                    } else if (count2 - count1 == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }
}
